/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
  const { currentUser } = initialState ?? {};
  console.log('currentUser', currentUser);
  const routes = currentUser?.routes;
  return {
    adminRouter:
      routes?.includes('ADMIN.ROUTE') ||
      routes?.includes('PERMISSION.ROUTE') ||
      routes?.includes('ROLE.ROUTE') ||
      routes?.includes('ADMIN.STRUCTURE.ROUTE') ||
      routes?.includes('ADMIN.DEPARTMENT.ROUTE') ||
      routes?.includes('ADMIN. DEPARTMENT.ROUTE') ||
      routes?.includes('TENANT.ROUTE'),
    admin: routes?.includes('ADMIN.ROUTE'),
    permission: routes?.includes('PERMISSION.ROUTE'),
    role: routes?.includes('ROLE.ROUTE'),
    structure: routes?.includes('ADMIN.STRUCTURE.ROUTE'),
    department: routes?.includes('ADMIN.DEPARTMENT.ROUTE'),
    _department: routes?.includes('ADMIN. DEPARTMENT.ROUTE'),
    tenant: routes?.includes('TENANT.ROUTE'),
    deviceRouter:
      routes?.includes('ROAD.ROUTE') ||
      routes?.includes('DEVICE.ROUTE') ||
      routes?.includes('SPACE.ROUTE'),
    road: routes?.includes('ROAD.ROUTE'),
    device: routes?.includes('DEVICE.ROUTE'),
    space: routes?.includes('SPACE.ROUTE'),
    heartRouter: routes?.includes('HEARTBEAT.ROUTE') || routes?.includes('IDENTIFY.ROUTE'),
    heartbeat: routes?.includes('HEARTBEAT.ROUTE'),
    identify: routes?.includes('IDENTIFY.ROUTE'),
    task: routes?.includes('BATCH.TASK.ROUTE'),
    system: routes?.includes('CONFIG.ROUTE') || routes?.includes('LOG.ROUTE'),
    config: routes?.includes('CONFIG.ROUTE'),
    log: routes?.includes('LOG.ROUTE'),
  };
}
